﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.Content.Page>" %>
<%@ Import Namespace="MethodWorx.CMS.Content" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript">
        $(document).ready(function () {
            $("#publishAll").click(function () {
                if (confirm("Are you sure you want to publish all the pages listed here")) {
                    $("input[type='checkbox']").attr("checked", "true");
                    $("#publish").click();
                }
            });
        })
    </script>

    <%using(Html.BeginForm())
      {%>
    <div class="formItem">
        <label>Publish Page:</label>
        <%=Model.Name%>
    </div>
    <div class="formItem">
        <label>Last Publised:</label>
        <%=Model.DatePublished.HasValue ? Model.DatePublished.ToString() : "Not Yet Published"%>
    </div>
    <div class="formItem">
        <label>Do you wish to publish the following child pages?</label>
        <div class="formBox" style="width:400px;overflow:auto;">
            <table style="width:100%">
            <thead>
                <tr style="background-color:silver;">
                    <td style="padding:2px;background-color:silver;">Page</td>
                    <td style="padding:2px;background-color:silver;">Last Published</td>
                </tr>
            </thead>
            <tbody>
           <%
          RenderChildPages(this.Model, 0);%>
          </tbody>
          </table>
        </div>
    </div>
    <div class="formItem">
        <button id="publish" name="submit" value="publish" type="submit">Publish</button>
        <button id="publishAll" value="cancel" type="button">Publish All</button>
        <button name="submit" value="cancel" type="submit">Cancel</button>

    </div>
    <%
      }%>
     <script runat="server">
        public void RenderChildPages(MethodWorx.CMS.Content.Page page, int i)
        {
            foreach(var child in page.ChildPages)
            {
                Response.Write("<tr>");
                Response.Write(
                    "<td style=\"float:none;padding-left:" + (i * 10) + "px\"><div><input type=\"checkbox\" name=\"children\" value=\"" +
                    child.Id + "\" />");
                switch(child.Status)
                {
                    case ContentStatus.AwaitingDelete:
                    case ContentStatus.PublishedAndAwaitingDelete:
                        Response.Write(
                            "<img src=\"" + Url.Content("~/images/icons/page_awaitingdelete.png") + "\" title=\"Awaiting Delete\" align=\"absmiddle\"/>");
                        break;
                    default:
                        Response.Write(
                            "<img src=\"" + Url.Content("~/images/icons/page.png") + "\" align=\"absmiddle\"/>");
                        break;
                }
                Response.Write("&nbsp;" + child.Name);
                Response.Write("</td>");
                if (child.DatePublished.HasValue)
                    Response.Write("<td style=\"float:right;padding-right:5px;padding-top:1px;\">" + child.DatePublished.ToString() + "</td>");
                Response.Write("</tr>");
                RenderChildPages(child, i + 1);
            }
        }
     </script>

</asp:Content>
